package com.yyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yyz.common.R;
import com.yyz.domain.Orders;
import com.yyz.dto.OrdersDto;
import com.yyz.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author yyz
 * @create 2023-07-27 16:38
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 支付
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("{}",orders);

        ordersService.submit(orders);

        return R.success("支付成功");
    }

    /**
     * 查询订单(手机端)
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<IPage<OrdersDto>> list(Integer page, Integer pageSize){
        IPage<OrdersDto> pageInfo = ordersService.list(page,pageSize);

        return R.success(pageInfo);
    }

    /**
     * 查询订单(pc端)
     * @param page
     * @param pageSize
     * @param number
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/page")
    public R<IPage<OrdersDto>> pageList(Integer page, Integer pageSize, Long number, LocalDate begin, LocalDate end){
        log.info("{},{},{},{},{}",page,pageSize,number,begin,end);

        IPage<OrdersDto> pageInfo = ordersService.pageList(page,pageSize,number,begin,end);

        return R.success(pageInfo);

    }

    /**
     * 派送
     * @param orders
     * @return
     */
    @PutMapping
    public R<String> status(@RequestBody Orders orders){
        ordersService.status(orders);

        return R.success("修改成功!");
    }
}
